<?php
#[水印图管理]
$sysnav = "file";

$sql = "SELECT count(id) FROM ".$prefix."upfiles WHERE 1";
$count = $DB->qg_count($sql);
unset($sql);

#[获取跳转页数，有小数点的进一位]
$psize = 15;
$allpage = $count / $psize;
$allpage_arr = explode(".",$allpage);
if($allpage_arr[1])
{
	$allpage = $allpage_arr[0]+1;
}

if($act=="reset")
{
	if(!$pageid)
	{
		$pageid = 1;
		Error("第".$pageid."页图片重新生成中...共".$allpage."页",$mainlink."?file=watermark&act=reset&pageid=1&type=".$type."");
	}

	$offet = $psize*($pageid-1);
	
	#[查找主题id]
	$sql = "SELECT thumb,thumb2,thumb3 FROM ".$prefix."msg WHERE 1";
	$msglist = $DB->qgGetAll($sql);
	foreach($msglist AS $key=>$value)
	{
		if($value["thumb"])
		{
			$msgid .= $value["thumb"].",";
		}
		if($value["thumb2"])
		{
			$msgid .= $value["thumb2"].",";
		}
		if($value["thumb3"])
		{
			$msgid .= $value["thumb3"].",";
		}
	}
	$msgid = substr($msgid,0,strlen($msgid)-1);
	$msgarr = explode(",",$msgid);
	unset($msglist,$msgid);
	
	$sql = "SELECT * FROM ".$prefix."upfiles WHERE 1 ORDER BY id ASC LIMIT ".$offet.", ".$psize."";
	$imglist = $DB->qgGetAll($sql);
	foreach($imglist AS $key=>$value)
	{
		if($type=="all")
		{
			$value["thumbfile"] = $GD->thumb($value["folder"].$value["filename"]);
			if(in_array($value["id"],$msgarr))
			{
				$sysid = getsysid(getmsgid($value["id"]));
				$picsize = picsize($sysid);
				$value["markfile"] = $GD->mark($value["folder"].$value["filename"],$picsize["width"],$picsize["height"]);
			}
			else
			{
				$value["markfile"] = $GD->mark($value["folder"].$value["filename"]);
			}
		}
		elseif($type=="thumb")
		{
			$value["thumbfile"] = $GD->thumb($value["folder"].$value["filename"]);
		}
		elseif($type=="mark")
		{
			if(in_array($value["id"],$msgarr))
			{
				$sysid = getsysid(getmsgid($value["id"]));
				$picsize = picsize($sysid);
				$value["markfile"] = $GD->mark($value["folder"].$value["filename"],$picsize["width"],$picsize["height"]);
			}
			else
			{
				$value["markfile"] = $GD->mark($value["folder"].$value["filename"]);
			}
		}
	}
	
	$pageid++;
	if($pageid<=$allpage)
	{
		Error("第".$pageid."页图片重新生成中...共".$allpage."页",$mainlink."?file=watermark&act=reset&pageid=".$pageid."&type=".$type."");
	}
	else
	{
		Error("全部图片重新生成成功",$mainlink."?file=watermark");
	}
}
else
{
	FOOT("watermark.qg");
}
?>